﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

namespace Model.Admin.Customer
{
    public class Customer
    {

        public string conn = ConfigurationManager.ConnectionStrings["OnlineFloralShopConnection"].ConnectionString;
        DataTable dt;

        public DataTable lisCus()
        {
            return Common.DataAccess.GetData(null, null, "GetAllCustomers");
        }
        public void FillListView(ListView list, DataTable dt)
        {
            list.DataSource = dt;
            list.DataBind();

        }
        // this is method used to  delete selected customer from listview 
        /* public void delete_Customer(ListView list)
         {
             // get 
             for (int i = 0; i < list.Items.Count; i++)
             {
                 if (((CheckBox)list.Items[i].FindControl("checked")).Checked==true)
                 {

                     deleteById(((Label)list.Items[i].FindControl("UserId")).Text);
                 }
            
             }
             //deleteById("member6", "delete_Customer");
        
         }*/
        /*public void deleteById(String id)
        {
            SqlConnection con = new SqlConnection(conn);
            con.Open();
            using (con)
            {
                SqlCommand cm = new SqlCommand();
                cm.Connection = con;
                cm.CommandType = CommandType.StoredProcedure;
                cm.CommandText = "delete_Customer";
                cm.Parameters.Add("@UserId", SqlDbType.NVarChar);
                cm.Parameters["@UserId"].Value = id;
                cm.ExecuteNonQuery();
            }

        }*/
        public DataTable SearchCusByName(string name)
        {
            SqlConnection con = new SqlConnection(conn);
            dt = new DataTable();

            con.Open();
            using (con)
            {
                SqlCommand cm = new SqlCommand();
                cm.Connection = con;
                cm.CommandType = CommandType.StoredProcedure;
                cm.CommandText = "searchCusByName";
                cm.Parameters.Add("@Name", SqlDbType.NVarChar);
                cm.Parameters["@Name"].Value = name;
                SqlDataAdapter da = new SqlDataAdapter(cm);
                da.Fill(dt);
                return dt;
            }
        }
        public DataTable SearhCusByfilter(string sql)
        {
            SqlConnection con = new SqlConnection(conn);
            dt = new DataTable();
            con.Open();
            using (con)
            {
                SqlCommand cm = new SqlCommand(sql, con);
                SqlDataAdapter da = new SqlDataAdapter(cm);
                da.Fill(dt);
                return dt;


            }
        }

        public DataTable updateUser(string userId, bool isapproved)
        {
            SqlConnection con = new SqlConnection(conn);
            dt = new DataTable();
            con.Open();
            using (con)
            {
                SqlCommand cm = new SqlCommand();
                cm.Connection = con;

                cm.CommandType = CommandType.StoredProcedure;
                cm.CommandText = "Updateuser";
                cm.Parameters.Add("@UserId", SqlDbType.NVarChar);
                cm.Parameters["@UserId"].Value = userId;
                cm.Parameters.Add("@IsAproved", SqlDbType.Bit);
                cm.Parameters["@IsAproved"].Value = isapproved;

                SqlDataAdapter da = new SqlDataAdapter(cm);
                da.Fill(dt);
                return dt;



            }

        }


        



    }
}
